home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_356 / algorhythms / source / drawform.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  188 lines

  1. /* drawform.c */
  2. /* Copyright 1990 Thomas E. Janzen All Rights Reserved */
  3. /*
  4. **  FACILITY:
  5. **
  6. **    AlgoRhythms music improviser on Commodore (TM) Amiga (TM)
  7. **    compiled with Lattice (TM) C 5.05
  8. **
  9. **  ABSTRACT:
  10. **
  11. **    Algorhythms improvises music over the MIDI serial port.
  12. **
  13. **  AUTHORS: Thomas E. Janzen
  14. **
  15. **  CREATION DATE:    26-MAR-1990
  16. **
  17. **  MODIFICATION HISTORY:
  18. **    DATE    NAME    DESCRIPTION
  19. **--
  20. */
  21. #include <intuition/intuition.h>
  22. #include <graphics/text.h>
  23. #include <proto/exec.h>
  24. #include <proto/graphics.h>
  25. #include <proto/intuition.h>
  26. #include <math.h>
  27.  
  28. struct Parameter {
  29.     double CenterCycle;
  30.     double CenterPhase;
  31.     double SpreadCycle;
  32.     double SpreadPhase;
  33. };
  34.  
  35. const static char PitchLabelString[16]="Pitch";
  36. const static char RhythmLabelString[16]="Rhythm";
  37. const static char DynamicsLabelString[16]="Dynamics";
  38. const static char TextureLabelString[16]="Texture";
  39.     
  40. static struct IntuiText PitchLabelTxt=
  41.     {1,1,JAM1,5,12,NULL,PitchLabelString,NULL};
  42. static struct IntuiText RhythmLabelTxt=
  43.     {1,1,JAM1,5,56,NULL,RhythmLabelString,&PitchLabelTxt};
  44. static struct IntuiText DynamicsLabelTxt=
  45.     {1,1,JAM1,5,100,NULL,DynamicsLabelString,&RhythmLabelTxt};
  46. static struct IntuiText TextureLabelTxt=
  47.     {1,1,JAM1,5,144,NULL,TextureLabelString,&DynamicsLabelTxt};
  48.  
  49. extern struct Window *w;
  50. extern struct RastPort *rp;
  51.  
  52. extern struct GfxBase *GfxBase;
  53. extern struct IntuitionBase *IntuitionBase;
  54. extern struct DOSBase *DOSBase;
  55. extern struct MathBase *MathBase;
  56.  
  57. void DrawForm(const double Duration,
  58.     const struct Parameter *PitchForm, 
  59.     const struct Parameter *RhythmForm, 
  60.     const struct Parameter *DynamicsForm,
  61.     const struct Parameter *TextureForm)
  62. {
  63.     static int Xlim,Ylim;
  64.     register int inttime=0;
  65.     register double curtime = 0.0;
  66.     double HeightRatio = 12.0;
  67.     double timeratio;
  68.  
  69.     double Spreadfixed, Mean, Top, Bottom;
  70.     register int intTop, intBottom;
  71.     double phase;
  72.  
  73.     int intLength=631;
  74.  
  75.     register int intMean;
  76.     register int Step=22;
  77.     
  78.     ClearScreen(rp);
  79.     SetAPen(rp,0);            /* Set foreground pen to white */
  80.     for (inttime=0;inttime<25;inttime++) {
  81.         Move(rp,0,inttime); /*erase part of screen */
  82.         Draw(rp,631,inttime); /*that ClearScreen didn't clear*/
  83.     }
  84.     Xlim = w->GZZWidth;
  85.     Ylim = w->GZZHeight;
  86.     intLength=Xlim;
  87.     Step=Ylim/8;
  88.     timeratio=((double)intLength)/(Duration);
  89.     HeightRatio=12*Ylim/200;
  90.     
  91.     SetAPen(rp,3);            /* Set foreground pen to white */
  92.     SetDrMd(rp,JAM1);        /* Draw with foreground pen */
  93.  
  94.     for (inttime=0;inttime<intLength;inttime++) {
  95.         curtime=(double)inttime/timeratio;
  96.         phase=2 * PI * curtime;
  97.         Spreadfixed=(1+
  98.         sin(phase/(PitchForm->SpreadCycle)+
  99.             PitchForm->SpreadPhase))/4.0;
  100.         Mean=
  101.         sin(phase/(PitchForm->CenterCycle)+
  102.             PitchForm->CenterPhase);
  103.         Top=Mean+(Spreadfixed); /*could be -1.5 to 1.5*/
  104.         Bottom=Mean-(Spreadfixed);
  105.         intMean=Step;
  106.         intBottom=-(Bottom*HeightRatio)+intMean;
  107.         intTop=-(Top*HeightRatio)+intMean;
  108.         Move(rp,inttime,intTop);
  109.         Draw(rp,inttime,intBottom);
  110.  
  111.         Spreadfixed=(1+
  112.         sin(phase/(RhythmForm->SpreadCycle)+
  113.             RhythmForm->SpreadPhase))/4.0;
  114.         Mean=
  115.         sin(phase/(RhythmForm->CenterCycle)+
  116.             RhythmForm->CenterPhase);
  117.         Top=Mean+(Spreadfixed); /*could be -1.5 to 1.5*/
  118.         Bottom=Mean-(Spreadfixed);
  119.         intMean=Step*3;
  120.         intBottom=-(Bottom*HeightRatio)+intMean;
  121.         intTop=-(Top*HeightRatio)+intMean;
  122.         Move(rp,inttime,intTop);
  123.         Draw(rp,inttime,intBottom);
  124.         
  125.         Spreadfixed=(1+
  126.         sin(phase/(DynamicsForm->SpreadCycle)+
  127.             DynamicsForm->SpreadPhase))/4.0;
  128.         Mean=
  129.         sin(phase/(DynamicsForm->CenterCycle)+
  130.             DynamicsForm->CenterPhase);
  131.         Top=Mean+(Spreadfixed); /*could be -1.5 to 1.5*/
  132.         Bottom=Mean-(Spreadfixed);
  133.         intMean=Step*5;
  134.         intBottom=-(Bottom*HeightRatio)+intMean;
  135.         intTop=-(Top*HeightRatio)+intMean;
  136.         Move(rp,inttime,intTop);
  137.         Draw(rp,inttime,intBottom);
  138.         
  139.         Top=(1+
  140.         sin(phase/(TextureForm->SpreadCycle)+
  141.             TextureForm->SpreadPhase))/2.0;
  142.         /*Top=SpreadFixed;*/
  143.         Bottom=-(Top);
  144.         intMean=Step*7;
  145.         intBottom=-(Bottom*HeightRatio)+intMean;
  146.         intTop=-(Top*HeightRatio)+intMean;
  147.         Move(rp,inttime,intTop);
  148.         Draw(rp,inttime,intBottom);
  149.     }
  150.     SetAPen(rp,1);
  151.     for(inttime=0;inttime<4;inttime++) {
  152.         Move(rp,0,Step*((2*inttime)+1));
  153.         Draw(rp,Xlim,Step*((2*inttime)+1));
  154.     }
  155.     PitchLabelTxt.TopEdge=Step*(1/2);
  156.     RhythmLabelTxt.TopEdge=Step*(5/2);
  157.     DynamicsLabelTxt.TopEdge=Step*(9/2);
  158.     TextureLabelTxt.TopEdge=Step*(13/2);
  159.     PrintIText(rp,&TextureLabelTxt,1,1);
  160. }
  161.  
  162. void DrawTime(const double CurTime, const double Duration)
  163. {
  164.     static int Xlim,Ylim;
  165.     register int inttime=0;
  166.  
  167.     double timeratio;
  168.  
  169.     double HeightRatio=12;
  170.  
  171.     int intMean;
  172.     SetAPen(rp,2);            /* Set foreground pen to white */
  173.  
  174.     Xlim = w->GZZWidth;
  175.     Ylim = w->GZZHeight;
  176.  
  177.     intMean=Ylim/8;
  178.     timeratio=((double)Xlim)/Duration;
  179.     HeightRatio=(12.0*Ylim)/200.0;
  180.     SetDrMd(rp,JAM1);        /* Draw with foreground pen */
  181.     inttime=(int)(CurTime*timeratio);
  182.     Move(rp,0,intMean);
  183.     Draw(rp,inttime,intMean);
  184.     SetAPen(rp,1);            /* Set foreground pen to white */
  185.     Draw(rp,Xlim,intMean);
  186. }
  187.  
  188.